<?php
/**
 * @filesource					ChooseGraveModel.class.php
 * @desc						墓地选址模型类
 * 
 * @author						houyining
 * @copyright					hou.yining@gmail.com	
 * @date						2011-05-04
 */

class ChooseGraveModel extends CommonModel{
	protected $_auto = array(
		array('create_time', 'time', MODEL::MODEL_INSERT, 'function'),
		array('creater_id', 'get_current_operator', MODEL::MODEL_INSERT, 'function'),
		array('creater_name', 'get_current_operator_name', MODEL::MODEL_INSERT, 'function'),
	);
	
	//取得选址信息列表
	public function getChooseGraveList(){
		$rs = $this->db->query('select a.name as customer_trend, b.*, c.name as customer_name, c.telephone from '.
								$this->tablePrefix.'customer_trend_type as a, '.$this->tablePrefix.'choose_grave as b, '.
								$this->tablePrefix.'general_customer as c where b.customer_trend_id=a.id and '.
								'b.applicant_id=c.id and a.status=1');
		return $rs;
	}
	
	//获取指定id的选址记录
	public function getChooseGraveInfo($id){
		$rs = $this->db->query('select a.name as customer_trend, b.*, c.name as customer_name, c.telephone from '.
								$this->tablePrefix.'customer_trend_type as a, '.$this->tablePrefix.'choose_grave as b, '.
								$this->tablePrefix.'general_customer as c where b.customer_trend_id=a.id and '.
								'b.applicant_id=c.id and a.status=1 and b.id='.$id);
		return $rs;
	}
	
	//获取指定申请人的所有选址记录
	public function getChooseGraveListByApplicant($applicant_id){
		return $this->where(array('applicant_id' => $applicant_id))->select();
	}
}
?>